
import string
import random
#随机生成20个长度在5至15的字符
comments = [''.join(random.choices(string.ascii_letters,k=random.randint(5,15))) for i in range(20)]

print(comments)
#（1）自定义函数方法解决
def get_brief_comments(comments):
    for comment in comments:
        yield comment if len(comment) <= 10 else comment[:10]+'...'

#自定义函数其实与内建函数map一样
brief_comments = map(lambda x : x if len(x)<=10 else x[:10]+'...',comments)
print(tuple(brief_comments))  #得到元组格式
